<?php
//	duong dan khi tao thumb thumb-137-113=> thumb-width-heigh
//	\uploads\articles\2009\11\thumb-137-113\1258509840-110717.jpg

// $filename ten file trong thu muc "\uploads\articles\2009\11\" 	VD: 1258509840-110717.jpg


error_reporting(0);
//error_reporting(E_ALL|E_STRICT);
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));


include_once (BASE_PATH."/ext/phpThumb/ThumbLib.inc.php");
include_once (BASE_PATH."/config/config.php");

$config ['upload_dir'] = $_SERVER ['DOCUMENT_ROOT'].'/uploads';

$thumbnail_width = 137;
$thumbnail_heigh = 113;

$upload_dir = $config ['upload_dir'].'/articles/'.date("Y").'/'.date("m");
$upload_dir_thumb = $upload_dir."/thumb-$thumbnail_width-$thumbnail_heigh";



$options = array('resizeUp' => true, 'jpegQuality'=>88);
$thumb = PhpThumbFactory::create($upload_dir."/".$filename, $options);
$thumb->adaptiveResize($thumbnail_width+10, $thumbnail_heigh+10);
$thumb->cropFromCenter($thumbnail_width, $thumbnail_heigh);
$thumb->save($upload_dir_thumb.'/'.$filename,'jpg');



$mem_usage = memory_get_usage(true);
echo "<br/>";
if ($mem_usage < 1024)
	echo $mem_usage." bytes";
elseif ($mem_usage < 1048576)
	echo round($mem_usage/1024,2)." kilobytes";
else
	echo round($mem_usage/1048576,2)." megabytes";
?>